<template>
  <div :class="className" :style="{ height: height, width: width }" />
</template>

<script>
// import { createRequire } from "module";
// const require = createRequire(import.meta.url);
// console.log(require, "require");

import * as echarts from "echarts";
// require('echarts/theme/macarons') // echarts theme
 import("echarts/theme/macarons"); // echarts theme
import resize from "./mixins/resize";
let chart =null

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: "chart",
    },
    width: {
      type: String,
      default: "100%",
    },
    height: {
      type: String,
      default: "300px",
    },
  },
  data() {
    return {
      // chart: null,
    };
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart();
    });
  },
  beforeDestroy() {
    if (!chart) {
      return;
    }
    chart.dispose();
    chart = null;
  },
  methods: {
    initChart() {
      chart = echarts.init(this.$el, "macarons");

      chart.setOption({
        tooltip: {
          trigger: "item",
          formatter: "{a} <br/>{b} : {c} ({d}%)",
        },
        legend: {
          left: "center",
          bottom: "10",
          data: ["北京", "上海", "澳门", "深圳", "杭州"],
        },
        series: [
          {
            name: "WEEKLY WRITE ARTICLES",
            type: "pie",
            // roseType: "radius",
            radius: [15, 95],
            center: ["50%", "38%"],
            data: [
              { value: 320, name: "北京" },
              { value: 240, name: "上海" },
              { value: 149, name: "澳门" },
              { value: 100, name: "深圳" },
              { value: 59, name: "杭州" },
            ],
            animationEasing: "cubicInOut",
            animationDuration: 2600,
          },
        ],
      });
    },
  },
};
</script>
